import { Controller, Get, Query, Param } from '@nestjs/common'
import { WebArticleService } from './web-article.service'

@Controller('web-article')
export class WebArticleController {
    constructor(private readonly webArticleService: WebArticleService) { }

    @Get()
    list (@Query() urlQuery: { pageIndex: string, pageSize: string, categoryId?: string, title?: string }) {
        const query = {
            categoryId: urlQuery.categoryId ? +urlQuery.categoryId : undefined,
            title: urlQuery.title,
            pageIndex: +urlQuery.pageIndex,
            pageSize: +urlQuery.pageSize
        }
        return this.webArticleService.list(query)
    }

    @Get('recommend')
    recommend () {
        return this.webArticleService.recommend()
    }

	@Get('total')
	getCountOfArticleAndCategory () {
		return this.webArticleService.getCountOfArticleAndCategory()
	}

    @Get(':id')
    detail (@Param('id') id: string) {
        return this.webArticleService.detail(+id)
    }

}
